package cn.zhoutingrui.pethome.mylistener;

import cn.zhoutingrui.pethome.myenum.JwtRasHolder;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.FileCopyUtils;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener
@Slf4j
public class SystemInitContextListener implements ServletContextListener {
    @Value("${Jwt.privateKey}")
    private String jwtRsaPub;
    @Value("${Jwt.publicKey}")
    private String jwtRsaPrivate;



    @SneakyThrows
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("我是监听器");
        JwtRasHolder.INSTANCE.setJwtRsaPubData(FileCopyUtils
                .copyToByteArray(this.getClass().getClassLoader().getResourceAsStream("hrm_auth_rsa")));
        JwtRasHolder.INSTANCE.setJwtRsaPrivateData(FileCopyUtils
                .copyToByteArray(this.getClass().getClassLoader().getResourceAsStream("hrm_auth_rsa.pub")));


        System.out.println("System is init finished!");

    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {

        log.info("System is Destroyed!");
    }
}
